home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / µSim 1.1 / FabLibsƒ / FabWList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-02  |  2.5 KB  |  129 lines  |  [TEXT/CWIE]

  1. #include    <StdLib.h>
  2. #include    "CursorBalloon.h"
  3. #include    "FabWmemman.h"
  4. #include    "FabWList.h"
  5.  
  6. typedef struct fabwlist FabWList;
  7.  
  8. struct fabwlist {
  9.     FabWList    *ptr;    // next in list
  10.     DialogRef    d;        // OS window
  11.     FabWindowPtr    f;    // my data
  12.     };
  13.  
  14. static FabWList    startOfWList = { nil, nil, nil };
  15. static UInt32    gWindowCount = 0;
  16.  
  17. #if    !defined(FabNoSegmentDirectives)
  18. #pragma segment Main
  19. #endif
  20.  
  21.  
  22. FabWindowPtr AddWindowToList(DialogRef d)
  23. {
  24. FabWList    *newElem;
  25.  
  26. newElem = ffcalloc(sizeof(struct fabwlist) + sizeof(struct FabWindowRec));
  27. if (newElem == nil)
  28.     return nil;
  29. else {
  30.     newElem->ptr = startOfWList.ptr;
  31.     startOfWList.ptr = newElem;
  32.  
  33.     newElem->d = d;
  34.     if (GetWindowKind(d) != kDialogWindowKind)
  35.         SetWindowKind(d, kFabWindowClass);
  36.  
  37.     //newElem->f = ffcalloc(sizeof(struct FabWindowRec));
  38.     newElem->f = (FabWindowPtr)(newElem + 1);
  39.     Zones(newElem->f) = (RgnBalloonCursHandle)NewHandle(0);
  40.     newElem->f->cntlList = NewHandle(0);
  41. // other initializations not needed because we allocate the structure with ffcalloc
  42.     ++gWindowCount;
  43.     }
  44. return newElem->f;
  45. }
  46.  
  47. void RemoveWindowFromList(DialogRef d)
  48. {
  49. FabWList    *newElem = &startOfWList;
  50. register RgnBalloonCursHandle    tempH;
  51. register RgnBalloonCursPtr    spanPtr;
  52. register unsigned long    i;
  53.  
  54.  
  55. while (newElem->ptr) {
  56.     if (newElem->ptr->d == d) {
  57.         tempH = Zones(newElem->ptr->f);
  58.         HLock((Handle)tempH);
  59.         spanPtr = *tempH;
  60.         
  61.         for (i = 0; i < NumObjects(newElem->ptr->f); i++, spanPtr++) {
  62.             DisposeRgn(spanPtr->zoneLocal);
  63.             DisposeRgn(spanPtr->zoneGlobal);
  64. // we do nothing with the CursHandles since they might be system cursors
  65.             }
  66.         DisposeHandle((Handle)tempH);
  67.         DisposeHandle(newElem->ptr->f->cntlList);
  68. // the caller knows whether CloseWindow or CloseDialog is to be called
  69. //        ffree(newElem->ptr->f);
  70. {    FabWList    *tmp;
  71.         tmp = newElem->ptr->ptr;
  72.         ffree(newElem->ptr);
  73.         newElem->ptr = tmp;
  74. }
  75.         --gWindowCount;
  76.         break;
  77.         }
  78.     newElem = newElem->ptr;
  79.     }
  80. }
  81.  
  82. FabWindowPtr GetFabWindowPtr(DialogRef d)
  83. {
  84. FabWList    *newElem = startOfWList.ptr;
  85.  
  86. if (d) {
  87.     while (newElem) {
  88.         if (newElem->d == d) {
  89.             return newElem->f;
  90.             }
  91.         newElem = newElem->ptr;
  92.         }
  93.     }
  94. return nil;
  95. }
  96.  
  97. void ForEachWindowDo(void (*actProc)(DialogRef))
  98. {
  99. DialogRef    d;
  100. FabWList    *newElem = startOfWList.ptr;
  101.  
  102. while (newElem) {
  103. /*    if (newElem->d == d) {
  104.         return newElem->f;
  105.         }*/
  106.     d = newElem->d;
  107.     newElem = newElem->ptr;
  108.     actProc(d);
  109.     }
  110.  
  111. }
  112.  
  113. UInt32 GetWindowCount(void)
  114. {
  115. return gWindowCount;
  116. }
  117.  
  118. #if    !defined(FabNoSegmentDirectives)
  119. #pragma segment Init
  120. #endif
  121.  
  122. void InitFabWListManager(void)
  123. {
  124. ffree(fmalloc(sizeof(struct fabwlist)));
  125. }
  126.  
  127.  
  128. // check out the last #pragma segment !!!!!
  129.